<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>react-demo-19</title>
    <link rel="preconnect" href="https://fonts.googleapis.com" />
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
    <link href="../../../js/font.css" rel="stylesheet" />
  </head>
  <style lang="scss">
    * {
      font-family: "Noto Sans SC", sans-serif;
    }

    body {
      display: flex;
      justify-content: flex-end;
    }

    body > div#main > * {
      display: flex;
      column-gap: 1rem;
      border-radius: 3px;
    }
  </style>
  <body>
    <!-- 准备容器 -->
    <div id="main"></div>

    <!-- 引入react核心库 -->
    <script
      type="text/javascript"
      src="../../../js/react.development.min.js"
    ></script>
    <!-- 引入react-dom，用于操作dom -->
    <script
      type="text/javascript"
      src="../../../js/react-dom.development.min.js"
    ></script>

    <!-- 引入prop-types -->
    <script src="../../../js/prop-types.js"></script>

    <!-- 引入babel，用于编译jsx -->
    <script src="../../../js/babel.min.js"></script>

    <!-- 此处一定要写babel，用于提示babel对该内容进行编译 -->
    <script type="text/babel">
      class Demo extends React.Component {
        state = {
          username: "",
          password: "",
        };
        usernameInput = (e) => {
          this.setState({
            username: e.target.value,
          });
        };
        passwordInput = (e) => {
          this.setState({
            password: e.target.value,
          });
        };
        handleSubmit = (event) => {
          event.preventDefault();
          alert("form: " + this.state.username + "; " + this.state.password);
        };
        render() {
          return (
            <form action="" onSubmit={this.handleSubmit}>
              <label>
                用户名：
                <input
                  type="text"
                  name="username"
                  onChange={this.usernameInput}
                />
              </label>
              <label>
                密码：
                <input
                  type="password"
                  name="password"
                  onChange={this.passwordInput}
                />
              </label>
              <button>Login</button>
            </form>
          );
        }
      }
      ReactDOM.render(<Demo />, document.getElementById("main"));
    </script>
  </body>
</html>
